/*-------------------------------------------------------------------------
 * CLR版本:     4.0.30319.42000
 * 创建人:      song
 * 创建时间：   2024/4/9 17:56:20
 * 功 能：      Range 绘制器
 *-------------------------------------------------------------------------*/

#if UNITY_EDITOR
namespace SCore.Editor.SShaderDraw
{
    using System.Collections.Generic;
    using UnityEditor;
    using UnityEngine;

    public class SRangeProp : SPropSuperBase<float>
    {
        float minfloat, maxfloat;

        public override void Draw(float space, float BtnSize = 400)
        {
            if (base.props.ContainsKey(base.name))
            {
                MaterialProperty prop = base.props[base.name];
                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(space);
                EditorGUILayout.LabelField(base.lable, fontStyle);
                setValue(EditorGUILayout.Slider(getValue(), minfloat, maxfloat));
                base.DrawResetBtn(BtnSize, () => { ResetDefaultValue(); });
                GUILayout.EndHorizontal();
            }
        }

        protected override float getValue()
        {
            return base.props[name].floatValue;
        }

        protected override void ResetDefaultValue()
        {
            base.props[base.name].floatValue = base.defaultValue;
        }

        protected override void setValue(float value)
        {
            base.props[name].floatValue = value;
        }

        public SRangeProp(string name, GUIContent lable, MaterialEditor materialEditor,
            Dictionary<string, MaterialProperty> props, float minfloat, float maxfloat) :
            base(name, lable, materialEditor, props, 1f)
        {
            this.minfloat = minfloat;
            this.maxfloat = maxfloat;
        }

        public SRangeProp(string name, GUIContent lable, MaterialEditor materialEditor,
            Dictionary<string, MaterialProperty> props, float defaultValue, float minfloat, float maxfloat) :
            base(name, lable, materialEditor, props, defaultValue)
        {
            this.minfloat = minfloat;
            this.maxfloat = maxfloat;
        }
    }
}
#endif